package com.example.robertluozizhao.framecollectdemo.adapter.base;
import androidx.recyclerview.widget.RecyclerView;
import com.example.robertluozizhao.framecollectdemo.common.Constants;

import java.util.List;

/**
 * Created by robert.luozizhao on 2018/2/2.
 */

public abstract class BaseReycleAdapter<D> extends RecyclerView.Adapter{

    protected List<D> sData;
    private int type = Constants.ITEM_TYPE_ONE;

    public BaseReycleAdapter(List<D> sData) {
        this.sData = sData;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

    }

    @Override
    public int getItemCount() {
        if (sData == null || sData.size() == 0) {
            return 0;
        }
        return sData.size();
    }

    @Override
    public int getItemViewType(int position) {
            switch (setCustomItemType(position)) {
                case Constants.ITEM_TYPE_ONE:
                    type = Constants.ITEM_TYPE_ONE;
                    return type;
                case Constants.ITEM_TYPE_TWO:
                    type = Constants.ITEM_TYPE_TWO;
                    return type;
            }
        return super.getItemViewType(position);
    }

    // 如果多个item 重写这个方法
    protected  int setCustomItemType(int position){
        return super.getItemViewType(position);
    };

    /**
     * 添加数据
     * @param d
     */
    public void addData(D d){
        if (sData!=null) {
            sData.add(d);
            notifyDataSetChanged();
        }
    }
}
